package com.hitemole.objects;

import java.util.Map;

import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.hitemole.interfaces.IAnimatedObject;

public class AnimatedGameObject implements IAnimatedObject{

	protected String name;
	protected Map<String,Animation> animation;
	protected Vector2 position;
	public float stateTime=0;
	public float xScale;
	public float yScale;
	protected String animationKey;
	protected Boolean drawAnimation=true;

	public Boolean getDrawAnimation() {
		return drawAnimation;
	}

	public void setDrawAnimation(Boolean drawAnimation) {
		this.drawAnimation = drawAnimation;
	}

	public AnimatedGameObject(String name, Map<String,Animation> animation, Vector2 position, float xScale, float yScale){
		this.name=name;
		this.animation=animation;
		this.position=position;
	}
	
	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return name;
	}

	@Override
	public void setAnimation(String animationName, Animation animationFrame) {
		// TODO Auto-generated method stub
		this.animation.put(animationName, animationFrame);
	}

	@Override
	public Map<String, Animation> getAnimation() {
		// TODO Auto-generated method stub
		return animation;
	}

	@Override
	public void setPosition(Vector2 position) {
		// TODO Auto-generated method stub
		this.position=position;
	}
	
	

	@Override
	public Vector2 getPosition() {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public void objectLoop(int delta) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void update(float delta) {
		// TODO Auto-generated method stub
		stateTime += delta;
	}
	
	public void setScale(float xScale2, float yScale2) {
		// TODO Auto-generated method stub
		this.xScale=xScale2;
		this.yScale=yScale2;
	}
	
	public void setAnimationKey(String animationKey){
		this.animationKey=animationKey;
	}
	
	public TextureRegion getCurrentAnimationFrame(){
		return animation.get(animationKey).getKeyFrame(stateTime);
	}
	
	public Animation getCurrentAnimation(){
		return animation.get(animationKey);
	}
	
	public Vector2 getRelativePosition(){
		return new Vector2(position.x*xScale,position.y*yScale);
	}
	
	public Vector2 getRelativeSize(){
		TextureRegion temp= animation.get(animationKey).getKeyFrame(0);
		return new Vector2(temp.getRegionWidth()*xScale, temp.getRegionHeight()*yScale);
	}

	@Override
	public void setRelativePosition(Vector2 position) {
		// TODO Auto-generated method stub
		this.position.x=position.x/xScale;
		this.position.y=position.y/yScale;
	}


}
